<template>
  <div class="home-container">
    <el-container>
      <el-aside width="200px" class="sidebar-container">
        <div class="sidebar-header">
          <div class="logo">系统管理</div>
        </div>
        <el-menu
            default-active="1-1"
            class="sidebar-menu"
            background-color="#2c3e50"
            text-color="#fff"
            active-text-color="#409EFF"
            router
        >
          <router-link to="/HomeView">
            <el-menu-item>
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
            </el-menu-item>
          </router-link>

          <router-link to="/HomeView/UserControllerView">
            <el-menu-item>
            <i class="el-icon-s-management"></i>
            <span slot="title">管理中心</span>
            </el-menu-item>
          </router-link>

          <el-menu-item index="1-3">
            <i class="el-icon-s-setting"></i>
            <span slot="title">系统设置</span>
          </el-menu-item>
          <el-menu-item index="1-4">
            <i class="el-icon-s-help"></i>
            <span slot="title">帮助中心</span>
          </el-menu-item>
        </el-menu>
        <div class="sidebar-footer">
          <el-button
              type="text"
              icon="el-icon-switch-button"
              class="logout-btn"
              @click="handleLogout"
          >
            退出登录
          </el-button>
        </div>
      </el-aside>

      <el-container class="main-container">
        <el-header class="app-header">
          <div class="header-content">
            <div class="welcome-message">
              欢迎回来，{{ username || '用户' }}！
            </div>
            <div class="user-info">
              <el-avatar icon="el-icon-user" class="user-avatar"></el-avatar>
            </div>
          </div>
        </el-header>

        <el-main class="app-main">
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "HomeView",
  data() {
    return {
      username: sessionStorage.getItem('username')
    }
  },
  methods: {
    handleLogout() {
      // 清除本地存储
      sessionStorage.removeItem('username');
      // 跳转到登录页
      this.$router.push('/');
      // 显示提示信息
      this.$message.success('已成功退出登录');
    }
  }
}
</script>

<style scoped>
.home-container {
  height: 100vh;
  overflow: hidden;
}

/* 侧边栏样式 */
.sidebar-container {
  background-color: #2c3e50;
  color: #fff;
  height: 100vh;
  /* 可根据需要调整内边距，避免内容拥挤 */
  padding-top: 15px;
  padding-bottom: 15px;
  transition: all 0.3s ease;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 0;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 1px;
}

.sidebar-menu {
  border-right: none;
  height: calc(100% - 130px);
  padding-top: 20px;
}

.el-menu-item {
  height: 50px;
  line-height: 50px;
  margin-bottom: 5px;
  transition: all 0.2s ease;
}

.el-menu-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.el-menu-item.is-active {
  background-color: #34495e;
  border-left: 3px solid #409EFF;
}

.sidebar-footer {
  padding: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.logout-btn {
  color: rgba(255, 255, 255, 0.7);
  width: 100%;
  justify-content: center;
  transition: all 0.2s ease;
}

.logout-btn:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.1);
}

/* 主内容区域样式 */
.main-container {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 头部样式 */
.app-header {
  background-color: #fff;
  color: #333;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 0 20px;
  height: 64px;
  line-height: 64px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.welcome-message {
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.user-info {
  display: flex;
  align-items: center;
}

.user-avatar {
  width: 36px;
  height: 36px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.user-avatar:hover {
  transform: scale(1.1);
}

/* 主内容区样式 */
.app-main {
  background-color: #f5f7fa;
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
</style>
